// [[ OnflowGenerator File UUID: 9f033a655b5a489491e8e30ec030a1d4  ]]
package com.itdct.onflow.system.file.service

import com.itdct.onflow.core.constant.CommonString
import com.itdct.onflow.core.constant.ReturnCode
import com.itdct.onflow.core.extend.*
import com.itdct.onflow.core.vo.RespPageVo
import com.itdct.onflow.core.vo.RespVo
import com.itdct.onflow.system.common.base.BaseSysService
import com.itdct.onflow.system.common.context.Context
import com.itdct.onflow.system.common.extend.dict
import com.itdct.onflow.system.file.entity.SysFileFailReasonEntity
import com.itdct.onflow.system.file.mapper.SysFileFailReasonMapper
import com.itdct.onflow.system.file.qo.SysFileFailReasonEditQo
import com.itdct.onflow.system.file.qo.SysFileFailReasonSearchQo
import com.itdct.onflow.system.file.vo.SysFileFailReasonDetailVo
import com.itdct.onflow.system.file.vo.SysFileFailReasonListVo
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

/**
 * @author DCTANT
 * @date 2025-09-28 16:52:23
 * @version 1.0
 * @description 系统文件错误信息服务
 */
@Service
class SysFileFailReasonService(
    val sysFileFailReasonMapper: SysFileFailReasonMapper
) : BaseSysService() {

    @Transactional(rollbackFor = [Exception::class])
    fun add(qo: SysFileFailReasonEditQo, context: Context): RespVo<Long> {
        val addEntity = qo.toEntity(SysFileFailReasonEntity::class.java)
        val id = sysFileFailReasonMapper.insertEx(addEntity)
        return success(id)
    }

    @Transactional(rollbackFor = [Exception::class])
    fun update(qo: SysFileFailReasonEditQo, context: Context): RespVo<Unit> {
        val updateEntity = sysFileFailReasonMapper.selectByIdEx(qo.id)
        qo.injectValue(updateEntity)
        sysFileFailReasonMapper.updateEx(updateEntity)
        return success()
    }

    fun delete(qo: SysFileFailReasonEditQo, context: Context): RespVo<Unit> {
        val ids = qo.ids ?: fail(ReturnCode.LACK_PARAM, CommonString.REQUIRE_DELETE_ID_LIST)
        val deleteEntities = sysFileFailReasonMapper.selectByIdsEx(ids)
        sysFileFailReasonMapper.deleteBatchEx(deleteEntities)
        return success()
    }

    fun detail(qo: SysFileFailReasonSearchQo, context: Context): RespVo<SysFileFailReasonDetailVo> {
        val id = qo.id ?: fail(ReturnCode.LACK_PARAM, CommonString.REQUIRE_ID)
        val vo = sysFileFailReasonMapper.findById(id) ?: fail(CommonString.ENTITY_NOT_FOUND_USAGE("系统文件错误信息", id))
        return success(vo.dict())
    }

    fun page(qo: SysFileFailReasonSearchQo, context: Context): RespPageVo<SysFileFailReasonListVo> {
        startPage(context)
        val pageData = sysFileFailReasonMapper.findByList(qo)
        return successPage(pageData.dict())
    }

// [[ OnflowGenerator Range (- selectFunctions -) Start ]]

// [[ OnflowGenerator Range (- selectFunctions -) End ]]
}